/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.edu.unmsm.pacis.shca.domain.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.*;

/**
 *
 * @author solriver
 */
@Entity
@Table(name = "distrito", catalog = "bdshca")
@NamedQueries({
    @NamedQuery(name = "Distrito.findAll", query = "SELECT d FROM Distrito d"),
    @NamedQuery(name = "Distrito.findByCcdi", query = "SELECT d FROM Distrito d WHERE d.distritoPK.ccdi = :ccdi"),
    @NamedQuery(name = "Distrito.findByNombredi", query = "SELECT d FROM Distrito d WHERE d.nombredi = :nombredi"),
    @NamedQuery(name = "Distrito.findByCcpp", query = "SELECT d FROM Distrito d WHERE d.distritoPK.ccpp = :ccpp"),
    @NamedQuery(name = "Distrito.findByCcdd", query = "SELECT d FROM Distrito d WHERE d.distritoPK.ccdd = :ccdd")})
public class District implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected DistrictPK districtPK;
    @Column(name = "NOMBREDI")
    private String nombredi;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "district")
    private List<Residence> residenceList;
    @JoinColumns({
        @JoinColumn(name = "CCPP", referencedColumnName = "CCPP", insertable = false, updatable = false),
        @JoinColumn(name = "CCDD", referencedColumnName = "CCDD", insertable = false, updatable = false)})
    @ManyToOne(optional = false)
    private Province province;

    public District() {
    }

    public District(DistrictPK districtPK) {
        this.districtPK = districtPK;
    }

    public District(String ccdi, String ccpp, String ccdd) {
        this.districtPK = new DistrictPK(ccdi, ccpp, ccdd);
    }

    public DistrictPK getDistrictPK() {
        return districtPK;
    }

    public void setDistrictPK(DistrictPK districtPK) {
        this.districtPK = districtPK;
    }

    public String getNombredi() {
        return nombredi;
    }

    public void setNombredi(String nombredi) {
        this.nombredi = nombredi;
    }

    public List<Residence> getResidenceList() {
        return residenceList;
    }

    public void setResidenceList(List<Residence> residenceList) {
        this.residenceList = residenceList;
    }

    public Province getProvince() {
        return province;
    }

    public void setProvince(Province province) {
        this.province = province;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (districtPK != null ? districtPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof District)) {
            return false;
        }
        District other = (District) object;
        if ((this.districtPK == null && other.districtPK != null) || (this.districtPK != null && !this.districtPK.equals(other.districtPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "pe.edu.unmsm.pacis.shca.domain.entity.Distrito[ distritoPK=" + districtPK + " ]";
    }
    
}
